<?
layout("/inc/win_layout.html",{title:sysTitle}){}
    ?>
<style>
	.col-md-3{float:left;}
	.col-md-9{float: left;width: 80%;padding-left: 0;}
</style>
<div class="panel" style="height: 570px;">
	<div class="panel-body pan" style="height: 570px; overflow: auto;">
		<div class="row" style="margin-bottom: 10px;margin-top:15px;">
			
			
			<div class="col-lg-6" style="width: 470px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label" style="line-height: 30px;">知识库</label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="parentclassname" type="text"  value="根目录" class="form-control" disabled="true" /> 
						<input id="parentClassid" type="hidden" value="0" class="form-control" />
						<!-- <span class="input-group-btn">
							<button  onclick="showCategorySid()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">请选择..</button>
							<button  onclick="deleteCategorySid()" type="button" data-toggle="dropdown" class="btn btn-sm btn-primary">清空</button>
						</span>	 -->
						<span class="input-group-btn"><button id="xuanze" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>	
					</div>
				</div>
			</div>
			
			
			<div class="col-lg-6" style="width: 470px; float:left;margin-right:-20px; display:inline;">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                    <option value="title">标题</option>
                    	</select>
                   </span> 
                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" />
                    	<!-- <span
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span> -->
				</div>
			</div>
			
		</div>
		
		
		<div class="row" >
			<!-- <div class="col-lg-3" style="padding-top: 10px;width:450px">
				<div class="input-group input-group-sm mbs">
					<label for="inputUsername" class="col-md-3 control-label">
					  <div align="right">专题
						<span class='require' id="fuji"></span></div>
	                </label>
					<div class="col-md-7">
						<div class="input-group input-group-sm mbs" >
							 <input id="parentclassname" type="text"  value="根目录" class="form-control" disabled="true" /> 
							 <input id="parentClassid" type="hidden" value="0" class="form-control" />
							<span class="input-group-btn"><button id="xuanze" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>
						</div>
					</div>
				</div>
				
			</div>		
			
			
			<div class="col-lg-3" style="padding-top: 10px;width:350px">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                    <option value="title">标题</option>
                    	</select>
                   </span> 
                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" />
                    	<span
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
				</div>
			</div> -->
			
			<div class="col-lg-12">
               <div class="tb-group-actions pull-left" id="searchingButton">
               		<input class="btn btn-sm btn-primary" style="margin-left: 25px;margin-bottom: 10px;" type="button" value="精确检索" onclick="get(1);"/>
               		<input class="btn btn-sm btn-primary" style="margin-left: 25px;margin-bottom: 10px;" type="button" value="模糊检索" onclick="get(0);"/>
               		<!-- <input class="btn btn-sm btn-primary" style="margin-left: 25px;margin-bottom: 10px;" type="button" value="清空全部" onclick="emptyAllseek();"/> -->
               	</div>
               <div class="tb-group-actions pull-right">
               		
               <span id="dataCount"></span></div>
           </div>
			
			<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
					<!-- <span >当前已选择<span id="Xuannum">0</span>条记录:</span> 
					<button class="btn btn-sm btn-primary" onclick="delePiLiang()">
						<i class="fa fa-check"></i>&nbsp; 删除多项
					</button>   -->
				</div>
			</div>
		</div>
		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th ><input type="checkbox" class="checkall" name="onecheckall" /></th>
					<th >序号</th>
					<th >资源类型</th>
					<th >标题</th>
					<th >创建人</th>
					<th >创建时间</th>
					<th >状态</th>
					<th >可操作</th>
				</tr>
			</thead>
			<tbody id="findUser">
			
			</tbody>
		</table>
		<div id="dataNull" class="panel-body"
				style="height: 50px; line-height: 50px;" align="center">
		</div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>
</div>
<script type="text/javascript">
	var curr;
	var searchType;
	var ztreeId = window.parent.getztreeId();
	
	$(function()  {
		//获取专题名称
		querySpecialDataList(curr,1);
	});
	function get(flag) {
		searchType = flag;
		querySpecialDataList(curr,searchType);
	}
	
	
	/* function querySpecialName() {
		$.ajax({
			type : "post",
			data : {},
			url : "listfindRepositoryProduct.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(res){
			
				var typeHtml = "<option value=''>--请选择--</option>";
				for ( var i = 0; i < res.length; i++) {
					typeHtml += "<option value='"+res[i].name+"'>"+res[i].name+"</option>";
				}
				$("#chargeType").html(typeHtml);
			}
		});
		
	} */
	
	
	function querySpecialDataList(curr,searchType){
		/* if ($("#parentClassid").val() == 0) {
			alert("请选择知识库！");
			return;
		} */
		
		$.getJSON("./queryApplicationClassDataList.do",
			{ 
				classesId:$("#parentClassid").val(),
				page : curr || 1,
				queryParams:$("#queryParams").val(),
        		text:$("#text").val(),
        		//classZh:$("#parentclassname").val(),
        		searchType:searchType
			},
			function(res) {
		
				//此处仅仅是为了演示变化的内容
				
				var dataRole = eval(res);
				var html='';
				var time=dataRole[0]["search"]["time"];
				var count=dataRole[0]["search"]["count"];
				$("#dataCount").html("共有 <label>"+count+"</label> 条记录");
				var data=dataRole[0]["search"]["data"];
				var dataRole2 = eval(data);
				var classList = dataRole[0]["classList"];
				var classZh = dataRole[0]["classZh"];
				
				
				$("#findUser").html("");
				var str = "";
				if (count > 0) {
					$("#dataNull").html("");
					$("#page2").css("display","block");
					$("#dataNull").css("display","none");
					for(var i= 0; i< dataRole2.length;i++){
						str += "<tr><td>"
           		 			+"<input type='checkbox' name='checkall' value='"+dataRole2[i]["id"]+"'/>"
					 		+"</td><td>" 
							+(i + 1)
							+ "</td><td> <label id=>"
							+ dataRole2[i]["classZh"]
							+ "</label></td><td><label >"
							+ delMul(dataRole2[i]["title"]+'')
							+ "</label></td><td><label >"
							+ dataRole2[i]["create_user"]
							+ "</label></td><td><label >"
							+ getDate(dataRole2[i]["create_time"])
							+ "</label></td><td><label >";
						var status = "";
						if (dataRole2[i]["status"] == 0) {
							status = "未通过";
						} else {
							status = "已通过";
						}
						str +=status
							+ "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"queryDetails('"
							+ dataRole2[i]["id"]+"','"+dataRole2[i]["classes_id"]
							+ "')\">"
							+ "详情"
							+ "</button>" 
							+ "</td></tr>";
					
						}
					$("#findUser").append(str);	
				
					laypage({
						cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
						pages :(Math.ceil(count/15)), //总页数
						skip : false, //是否开启跳页
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						curr : curr || 1,
						last : false,//(Math.ceil(dataRole[0]["search"]["count"]/$("#pageSize").val())),
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								querySpecialDataList(obj.curr,searchType);
								//var curr = obj.curr;
								curr = obj.curr;
							}
						}
					});

					
				} else {
					
					$("#page2").css("display","none");
					$("#dataNull").css("display","block");
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
		});
	
	}
	
	
	//选择父类
	function saveclassZTree() {
		parent.layer.open({
			type : 2,
			area : [ '400px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-Classes-class-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}

	//详情
	function queryDetails(id,classesId){
		window.parent.queryDetails(id,classesId);
	}
	
	
	function save(){
	
		var value=[];
		$("input[name='checkall']:checked").each(function(){
			value.push($(this).val());
		});
		if (value.length > 0) {
			$.ajax({
				type : "post",
				url : "applicationSpecialDataAddMethod.do",
				dataType : "json",
				data :{
						"ids":value,
						"ztreeId":ztreeId
				},
				traditional : true,
				async : false,
				success : function(res) {
					if(res[0].data == '0'){
						
						var index = parent.layer.getFrameIndex(window.name);
						window.parent.get(1);
						parent.layer.msg('提交成功');
						parent.layer.close(index);
						
					}else{
						parent.layer.msg('添加失败！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
				
			});
		
		
		
		}
	}
	
	
	//字符串转时间格式  
	function getDate(strDate) {
		var time='';
		for(var key in strDate){
			var text = new Date(strDate[key]["time"]).format("yyyy-MM-dd hh:mm:ss");
			time+=text+"  ";
		}
		
		return time;
	} 
	
	//日期格式化
	Date.prototype.format = function (fmt) { //author: meizz 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	};

	//删除多语种前面的英文
	function delMul(str){
		var temp=str;
		if(temp.indexOf("|")>-1){
			temp=temp.substr(temp.indexOf("|")+1,temp.length);
		}else{
			temp=temp;
		}
		return temp;
	}
</script>
